<?php
require 'settings.php';
require 'db.php';

if( isset( $_POST['pricelist_id'] ) )
{
	$pl_id = $_POST['pricelist_id'];
}

if( isset( $_POST['pricelist_name'] ) )
{
	$pl_name = $_POST['pricelist_name'];
}
?>

<html>
<head>
<title><?php echo $corp_name?> Industry Manager - Pricelist "<?php echo $pl_name ?>"</title>

<style type="text/css">
table, th, td
{
border: 1px solid black;
border-collapse: collapse;
padding: 5px;
}
</style>

</head>
<body>
<h1 class=c_page_title>Pricelist "<?php echo $pl_name ?>"</h1>

<form name="recalc_pricelist" action="recalc_pricelist.php" method="post" >
<input name="pricelist_id" type="hidden" value="<?php echo $pl_id ?>" />
<input name="pricelist_name" type="hidden" value="<?php echo $pl_name ?>" />
<input type="submit" value="Recalculate this pricelist with latest data" />
</form>

</form>
<table>
<tr><td style="font-weight:bold">Name</td><td style="font-weight:bold">Build cost</td><td style="font-weight:bold">Price</td><td style="font-weight:bold">Replacement cost</td></tr>

<?php
$smf = '[left][size=18px][b]'.$pl_name.'[/b][/size][/left]'."\n".'[table]'."\n"; //output for smf
$smf .= '[tr][td][center][b]       Name       [/b][/center][/td][td][center][b]            Price[/b][/center][/td][td][center][b]            Replacement[/b][/center][/td][/tr]'."\n";

$pricelist_get->bind_param( 'i', $pl_id );
$pricelist_get->bind_result( $prod_it, $item_id, $item_name, $item_build_cost, $item_price, $item_replacement, $item_mat_volume );
$pricelist_get->execute();
while( $pricelist_get->fetch() )
{
	echo '<tr><td style="text-align:left">'.$item_name.'</td><td style="text-align:right">'.number_format($item_build_cost, 2, '.', ',').'</td><td style="text-align:right">'.number_format($item_price, 2, '.', ',').'</td><td style="text-align:right">'.number_format($item_replacement, 2, '.', ',').'</td></tr>';

	$smf .= '[tr][td][left]'.$item_name.'[/left][/td][td][right]'.number_format($item_price, 2, '.', ',').'[/right][/td][td][right]'.number_format($item_replacement, 2, '.', ',').'[/right][/td][/tr]'."\n";
}
$pricelist_get->close();
$smf .= '[/table]';
?>

</table>

<?php
echo '<br/><br/>SMF-compatible table (paste to forums):<br /><pre style="border:1px solid black">';
echo $smf;
echo '</pre>';
?>

<br />
<a href="view_pricelists.php">View pricelists</a><br />
<a href="index.php">Back to main screen</a>
</body>
</html>